﻿using LinqKit;
using Management.Auxiliary;
using System.Linq;

namespace Management.Core.ReportConfig
{
    public class ReportConfigManager:BaseManager<ReportConfig>
    {
        public Paging<ReportConfig> FindPageList(Paging<ReportConfig> pagingReportConfig, int? adminid, string adminName, int? order)
        {
            //查询表达式
            var _where = PredicateBuilder.New<ReportConfig>(true);
            if (adminid != null)
                _where = _where.And(u => u.AdminID == (int)adminid);
            if(!string.IsNullOrEmpty(adminName))
            {
                _where = _where.And(u => u.Admin.Accounts == adminName);
            }
            //排序
            OrderParam _orderParam;
            switch (order)
            {
                case 0://ID升序
                    _orderParam = new OrderParam() { PropertyName = "ReportConfigID", Method = OrderMethod.ASC };
                    break;
                case 1://ID降序
                    _orderParam = new OrderParam() { PropertyName = "ReportConfigID", Method = OrderMethod.DESC };
                    break;
                case 2://创建时间降序
                    _orderParam = new OrderParam() { PropertyName = "Created_at", Method = OrderMethod.ASC };
                    break;
                case 3://创建时间升序
                    _orderParam = new OrderParam() { PropertyName = "Created_at", Method = OrderMethod.DESC };
                    break;
                default://ID降序
                    _orderParam = new OrderParam() { PropertyName = "ReportConfigID", Method = OrderMethod.DESC };
                    break;
            }
            pagingReportConfig.Items = Repository.FindPageList(pagingReportConfig.PageSize, pagingReportConfig.PageIndex, out pagingReportConfig.TotalNumber, _where, _orderParam).ToList();
            return pagingReportConfig;
        }
    }
}
